package me.jessyan.armscomponent.app.mvp.ui.fragment;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.jess.arms.base.BaseFragment;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.ViewPagerHelper;

import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import me.jessyan.armscomponent.commonsdk.core.RouterHub;
import me.jessyan.armscomponent.app.R;
import me.jessyan.armscomponent.app.di.component.DaggerExploreVideoCourseComponent;
import me.jessyan.armscomponent.app.mvp.contract.explore.ExploreVideoCourseContract;
import me.jessyan.armscomponent.app.mvp.presenter.explore.ExploreVideoCoursePresenter;
import me.jessyan.armscomponent.app.mvp.ui.adapter.ExplorePagerAdapter;
import me.jessyan.armscomponent.app.mvp.ui.widget.ScaleCircleNavigator;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * <p>
 * Author: Taozebi
 * Date: 09/03/2021 14:43
 * Description: describe of this class
 */
@Route(path = RouterHub.EXPLORE_HOME_VIDEO_FRAGMENT)
public class ExploreVideoCourseFragment extends BaseFragment<ExploreVideoCoursePresenter> implements ExploreVideoCourseContract.View {
    private static final Integer[] CHANNELS = new Integer[]{R.drawable.explore_advertisement_01,R.drawable.explore_advertisement_02,R.drawable.explore_advertisement_03,R.drawable.explore_advertisement_04};
    private List<Integer> mDataList = Arrays.asList(CHANNELS);
    @BindView(R.id.explore_vp_video)
    ViewPager mViewPager;
    @BindView(R.id.explore_magic_indicator_video)
    MagicIndicator magicIndicator;
    ExplorePagerAdapter mPagerAdapter;

    public static ExploreVideoCourseFragment newInstance() {
        ExploreVideoCourseFragment fragment = new ExploreVideoCourseFragment();
        return fragment;
    }

    @Override
    public void setupFragmentComponent(@NonNull AppComponent appComponent) {
        DaggerExploreVideoCourseComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.explore_fragment_video_course, container, false);
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

        initViewPager();

        initMagicIndicator();
    }

    private void initViewPager(){
        mPagerAdapter = new ExplorePagerAdapter(mDataList);
        mViewPager.setAdapter(mPagerAdapter);
    }

    private void initMagicIndicator() {
        magicIndicator.setBackgroundColor(Color.WHITE);
        ScaleCircleNavigator scaleCircleNavigator = new ScaleCircleNavigator(getActivity());
        scaleCircleNavigator.setCircleCount(CHANNELS.length);
        scaleCircleNavigator.setNormalCircleColor(Color.LTGRAY);
        scaleCircleNavigator.setSelectedCircleColor(Color.DKGRAY);
        scaleCircleNavigator.setCircleClickListener(new ScaleCircleNavigator.OnCircleClickListener() {
            @Override
            public void onClick(int index) {
                mViewPager.setCurrentItem(index);
            }
        });
        magicIndicator.setNavigator(scaleCircleNavigator);
        ViewPagerHelper.bind(magicIndicator, mViewPager);

    }

    @Override
    public void setData(@Nullable Object data) {

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {

    }
}
